package net.towee.server.ftp.files;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import net.towee.model.account.AccountGroup;
import net.towee.model.repo.DocumentNode;
import net.towee.server.persistence.AttachmentStore;
import net.towee.server.persistence.DiscussionStore;
import net.towee.server.persistence.DocumentStore;

import org.apache.ftpserver.ftplet.FtpFile;

public class DocumentNodeFtpFile extends AbstractFtpFile {

	private final DocumentNode node;
	private final AccountGroup group;
	private final DocumentStore docStore;
	private final AttachmentStore attStore;
	private final DiscussionStore discStore;

	public DocumentNodeFtpFile(DocumentNode node, AccountGroup group, DocumentStore docStore,
			AttachmentStore attStore, DiscussionStore discStore) {
		
		super(  node.getDocumentIdentity().getName(), 
				true, 
				0, 
				group.getGroupIdentity().getAlias(), 
				node.getDocumentIdentity().getAuthor().getFullName(), FtpFileType.DOCUMENT_NODE, 
				"/"	+ group.getGroupIdentity().getAlias() + node.getPath() + "/"
						+ node.getDocumentIdentity().getName());

		this.node = node;
		this.group = group;
		this.docStore = docStore;
		this.attStore = attStore;
		this.discStore = discStore;
	}

	@Override
	public long getLastModified() {
		return 0;
	}

	@Override
	public List<FtpFile> listFiles() {
		// Create empty list
		List<FtpFile> files = new ArrayList<FtpFile>();

		// Add document data and attachment ftp files
		files.add(new DocumentDataFtpFile(node, docStore, discStore));
		files.add(new AttachmentsListFtpFile(node, docStore, attStore));

		return files;
	}

	@Override
	public OutputStream createOutputStream(long offset) throws IOException {
		return null;
	}

	@Override
	public InputStream createInputStream(long offset) throws IOException {
		return null;
	}

}
